using System;
using Prism.Services.Dialogs;
using PrismPractice.Const;

namespace PrismPractice.Core.Prism
{
	public static class DialogHelper
    {
	    /// <summary>
	    /// [扩展方法] 使用弹窗服务进行弹窗（指定了默认的窗口名称）<para/>
	    /// 需配合 <see cref="MyDialogService"/> 进行使用
	    /// </summary>
	    /// <param name="dialogService">对话框服务</param>
	    /// <param name="name">代表弹窗界面的名称</param>
	    /// <param name="callback">结果回调</param>
	    /// <param name="windowName">自定义窗口名称（默认为 CustomDialogWindow，传空则不设置自定义窗口）</param>
	    public static void ShowDialog(this IDialogService dialogService, string name, Action<IDialogResult> callback = null, string windowName = WindowNames.SECOND_SCREEN_WINDOW)
	    {
		    ShowDialog(dialogService, name, null, callback, windowName);
	    }

		/// <summary>
		/// [扩展方法] 使用弹窗服务进行弹窗（可传递 ViewModel）<para/>
		/// 需配合 <see cref="MyDialogService"/> 进行使用
		/// </summary>
		/// <param name="dialogService">对话框服务</param>
		/// <param name="name">代表弹窗界面的名称</param>
		/// <param name="viewModel">视图模型，作为界面的 DataContext</param>
		/// <param name="callback">结果回调</param>
		/// <param name="windowName">自定义窗口名称（默认为空，不设置自定义窗口）</param>
		public static void ShowDialog(this IDialogService dialogService, string name, object viewModel, Action<IDialogResult> callback = null, string windowName = null)
		{
			var paras = new DialogParameters { { Keys.MY_DIALOG_SERVICE_PARA_VM_KEY, viewModel } };

			if(string.IsNullOrWhiteSpace(windowName))
			{
				dialogService.ShowDialog(name, paras, callback);
			}
			else
			{
				dialogService.ShowDialog(name, paras, callback, windowName);
			}
		}

        /// <summary>
        /// [扩展方法] 使用弹窗服务进行弹窗（非模态，可传递 ViewModel）<para/>
        /// 需配合 <see cref="MyDialogService"/> 进行使用
        /// </summary>
        /// <param name="dialogService">对话框服务</param>
        /// <param name="name">代表弹窗界面的名称</param>
        /// <param name="viewModel">视图模型，作为界面的 DataContext</param>
        /// <param name="callback">结果回调</param>
        /// <param name="windowName">自定义窗口名称（默认为空，不设置自定义窗口）</param>
        public static void Show(this IDialogService dialogService, string name, object viewModel, Action<IDialogResult> callback = null, string windowName = null)
		{
			var paras = new DialogParameters { { Keys.MY_DIALOG_SERVICE_PARA_VM_KEY, viewModel } };

			if(string.IsNullOrWhiteSpace(windowName))
			{
				dialogService.Show(name, paras, callback);
			}
			else
			{
				dialogService.Show(name, paras, callback, windowName);
                //dialogService.Show(name, paras, null, WindowNames.SECOND_SCREEN_WINDOW);
            }
        }
	}
}
